﻿#if UNITY_EDITOR
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEditor;

public class MiaoEdtiorUtility
{
    /// <summary>
    /// 获取该目录的下所有类型（目录下只能放置该类型（文件夹也不可以））
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="folderPath"></param>
    /// <returns></returns>
    public static GameObject[] FastLoadAllGameObjectAtFolder(string folderPath)
    {
        var fileList = MiaoPath.GetFolderFiles(folderPath);
        int length = fileList.Length;
        GameObject[] result = new GameObject[length / 2];


        for(int i=0;i< length; i++)
        {
            if (fileList[i].EndsWith(".meta")) continue;
            var asset = AssetDatabase.LoadAssetAtPath<GameObject>(fileList[i]);
            result[i / 2] = asset;
        }
        return result;
    }
    /// <summary>
    /// 获取该目录的下所有类型（目录下只能放置该类型（文件夹也不可以））
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="folderPath"></param>
    /// <returns></returns>
    public static T[] FastLoadAllDataAtFolder<T>(string folderPath) where T:Object
    {
        var fileList = MiaoPath.GetFolderFiles(folderPath);
        int length = fileList.Length;
        T[] result = new T[length / 2];


        for (int i = 0; i < length; i++)
        {
            if (fileList[i].EndsWith(".meta")) continue;
            var asset = AssetDatabase.LoadAssetAtPath<T>(fileList[i]);
            result[i / 2] = asset;
        }
        return result;
    }
}

#endif